package com.rtzh.learnkotlin.broadcastreceiver

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AlertDialog
import com.rtzh.learnkotlin.ui.LoginActivity
import com.rtzh.learnkotlin.uitls.ActivityCollector

class ForceReceiverReceiver : BroadcastReceiver() {
    override fun onReceive(context: Context, intent: Intent?) {
        AlertDialog.Builder(context).apply {
            setTitle("Warning")
            setMessage("You are forced tobe offline.Please try to login again")
            setCancelable(false)
            setPositiveButton("OK") { _, _ ->
                ActivityCollector.finishAll() // 销毁所有Activity
                val i = Intent(context, LoginActivity::class.java)
                context.startActivity(i) // 重新启动LoginActivity
            }
            show()
        }
    }


}
